<template>
  <view class="service-page">
    <!-- 顶部搜索栏 -->
    <service-search-bar
      v-model:value="searchKeyword"
      @search="handleSearch"
    />
    
    <!-- 轮播图 -->
    <service-banner
      :banners="banners"
      @click="handleBannerClick"
    />
    
    <!-- 服务分类 -->
    <service-categories
      :categories="categories"
      @click="handleCategoryClick"
    />
    
    <!-- 热门服务 -->
    <service-list
      title="热门服务"
      :services="hotServices"
      @service-click="handleServiceClick"
      @more-click="goToAllServices"
    />
    
    <!-- 代拿代寄服务 -->
    <service-list
      title="代拿代寄服务"
      :services="expressServices"
      @service-click="handleServiceClick"
      @more-click="() => goToCategoryDetail(1)"
    />
    
    <!-- 学习辅导服务 -->
    <service-list
      title="学习辅导服务"
      :services="studyServices"
      @service-click="handleServiceClick"
      @more-click="() => goToCategoryDetail(2)"
    />
    
    <!-- 快捷服务入口 -->
    <service-quick-menu
      :services="quickServices"
      @click="handleQuickServiceClick"
    />
  </view>
</template>

<script setup>
import { ref } from 'vue';
import ServiceSearchBar from '@/components/service/ServiceSearchBar.vue';
import ServiceBanner from '@/components/service/ServiceBanner.vue';
import ServiceCategories from '@/components/service/ServiceCategories.vue';
import ServiceList from '@/components/service/ServiceList.vue';
import ServiceQuickMenu from '@/components/service/ServiceQuickMenu.vue';

// 搜索关键词
const searchKeyword = ref('');

// 轮播图数据
const banners = [
  { image: 'https://picsum.photos/seed/banner1/750/300' },
  { image: 'https://picsum.photos/seed/banner2/750/300' },
  { image: 'https://picsum.photos/seed/banner3/750/300' }
];

// 服务分类
const categories = [
  { id: 1, name: '代拿代寄', icon: '📦' },
  { id: 2, name: '远程打印', icon: '🖨️' },
  { id: 3, name: '学习辅导', icon: '📚' },
  { id: 4, name: '刷乐跑', icon: '🏃' },
  { id: 5, name: '代购早餐', icon: '🍔' },
  { id: 6, name: '课外辅导', icon: '📝' },
  { id: 7, name: '流量卡', icon: '📶' },
  { id: 8, name: '全部服务', icon: '✨' },
];

// 热门服务
const hotServices = [
  { 
    id: 1, 
    title: '快递代拿服务', 
    image: 'https://picsum.photos/seed/service1/300/200', 
    price: '¥3起', 
    sales: 235,
    hot: true
  },
  { 
    id: 2, 
    title: '远程打印服务 黑白/彩印', 
    image: 'https://picsum.photos/seed/service2/300/200', 
    price: '¥0.5/页起', 
    sales: 189,
    hot: true
  },
  { 
    id: 3, 
    title: '刷乐跑跑腿服务', 
    image: 'https://picsum.photos/seed/service3/300/200', 
    price: '¥8起/公里', 
    sales: 125,
    hot: true
  },
  { 
    id: 4, 
    title: '毕业设计辅导', 
    image: 'https://picsum.photos/seed/service4/300/200', 
    price: '¥200起', 
    sales: 78,
    hot: false
  },
];

// 代拿代寄服务
const expressServices = [
  { 
    id: 1, 
    title: '快递代拿服务', 
    image: 'https://picsum.photos/seed/express1/300/200', 
    price: '¥3起', 
    sales: 235,
    tag: '特惠',
    tagColor: '#ff6b6b'
  },
  { 
    id: 5, 
    title: '快递代寄服务', 
    image: 'https://picsum.photos/seed/express2/300/200', 
    price: '¥5起', 
    sales: 158,
    tag: '新上线',
    tagColor: '#4d96ff'
  },
];

// 学习辅导服务
const studyServices = [
  { 
    id: 2, 
    title: '远程打印服务 黑白/彩印', 
    image: 'https://picsum.photos/seed/study1/300/200', 
    price: '¥0.5/页起', 
    sales: 189,
    tag: '特惠',
    tagColor: '#ff6b6b'
  },
  { 
    id: 4, 
    title: '毕业设计辅导', 
    image: 'https://picsum.photos/seed/study2/300/200', 
    price: '¥200起', 
    sales: 78,
    tag: '推荐',
    tagColor: '#22b07d'
  },
];

// 快捷服务
const quickServices = [
  { id: 3, name: '刷乐跑', icon: '🏃' },
  { id: 2, name: '远程打印', icon: '🖨️' },
  { id: 5, name: '代购早餐', icon: '🍔' },
  { id: 1, name: '快递代拿', icon: '📦' },
];

// 搜索处理
const handleSearch = () => {
  if (!searchKeyword.value.trim()) return;
  uni.navigateTo({
    url: `/pages/service/search?keyword=${encodeURIComponent(searchKeyword.value)}`
  });
};

// 处理轮播图点击
const handleBannerClick = ({ item, index }) => {
  console.log('点击轮播图:', item, index);
  // 这里可以根据轮播图配置跳转到相应页面
  // 比如活动页面、服务详情等
};

// 处理分类点击
const handleCategoryClick = ({ category, index }) => {
  goToServiceCategory(category.id);
};

// 处理服务点击
const handleServiceClick = ({ service, index }) => {
  goToServiceDetail(service.id);
};

// 处理快捷服务点击
const handleQuickServiceClick = ({ service, index }) => {
  goToServiceDetail(service.id);
};

// 跳转到服务分类
const goToServiceCategory = (categoryId) => {
  uni.navigateTo({
    url: `/pages/service/category?id=${categoryId}`
  });
};

// 跳转到查看全部服务
const goToAllServices = () => {
  uni.navigateTo({
    url: '/pages/service/category?id=0'
  });
};

// 跳转到服务详情
const goToServiceDetail = (serviceId) => {
  uni.navigateTo({
    url: `/pages/service/detail?id=${serviceId}`
  });
};

// 跳转到分类详情
const goToCategoryDetail = (categoryId) => {
  uni.navigateTo({
    url: `/pages/service/category?id=${categoryId}`
  });
};
</script>

<style lang="scss" scoped>
.service-page {
  min-height: 100vh;
  background-color: #f7f8fa;
  padding-bottom: 20px;
}

.service-search {
  background-color: #07c160;
  padding: 10px 15px;
  position: sticky;
  top: 0;
  z-index: 100;
  
  &__box {
    height: 36px;
    background-color: #ffffff;
    border-radius: 18px;
    display: flex;
    align-items: center;
    padding: 0 15px;
  }
  
  &__icon {
    margin-right: 6px;
    color: #999;
  }
  
  &__input {
    flex: 1;
    height: 36px;
    font-size: 14px;
  }
}

.service-banner {
  width: 100%;
  height: 150px;
  
  &__image {
    width: 100%;
    height: 100%;
    border-radius: 0 0 16px 16px;
  }
}

.service-categories {
  display: flex;
  flex-wrap: wrap;
  background-color: #ffffff;
  padding: 15px 10px;
  margin: 10px 0;
  border-radius: 12px;
  margin: 15px;
}

.service-category {
  width: 25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  
  &__icon {
    font-size: 28px;
    margin-bottom: 8px;
  }
  
  &__name {
    font-size: 13px;
    color: #333;
  }
}

.service-section {
  background-color: #ffffff;
  border-radius: 12px;
  margin: 15px;
  padding: 15px;
  
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
  }
  
  &__title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    position: relative;
    padding-left: 10px;
    
    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 4px;
      height: 16px;
      background-color: #07c160;
      border-radius: 2px;
    }
  }
  
  &__more {
    font-size: 13px;
    color: #999;
  }
}

.service-items {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -7.5px;
}

.service-item {
  width: calc(50% - 15px);
  margin: 0 7.5px 15px;
  border-radius: 8px;
  overflow: hidden;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  
  &__top {
    position: relative;
    width: 100%;
    height: 100px;
  }
  
  &__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  &__tag {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 12px;
    color: #ffffff;
    background-color: #ff6b6b;
    padding: 2px 6px;
    border-radius: 4px;
  }
  
  &__title {
    padding: 8px 10px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  &__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 10px;
  }
  
  &__price {
    font-size: 15px;
    font-weight: bold;
    color: #ff6b6b;
  }
  
  &__sales {
    font-size: 12px;
    color: #999;
  }
}

.service-quick {
  background-color: #ffffff;
  border-radius: 12px;
  margin: 15px;
  padding: 15px;
  
  &__title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 15px;
  }
  
  &__items {
    display: flex;
    flex-wrap: wrap;
  }
  
  &__item {
    width: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
  }
  
  &__icon {
    width: 50px;
    height: 50px;
    background-color: #f0f0f0;
    border-radius: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 8px;
  }
  
  &__name {
    font-size: 13px;
    color: #333;
  }
}
</style>